//
//  SYLoginUserModel.m
//  SanYiTeaching
//
//  Created by 郑浩然 on 2019/6/5.
//  Copyright © 2019年 SanYi. All rights reserved.
//

#import "SYLoginUserModel.h"
#define kFileName @"accounts.data"
#define kCurrentName @"currentAccount.data"

#define kFilePath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:kFileName]
#define kPermissionsPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:kPermissionsName]
@implementation SYLoginUserModel
singleton_implementation(SYLoginUserModel)

- (instancetype)init {
    if (self = [super init]) {
        _userinfo = [NSKeyedUnarchiver unarchiveObjectWithFile:kFilePath];
    }
    return self;
}
- (void)addUserModel:(UserInformationModel *)userModel {
    _userinfo = userModel;
    [NSKeyedArchiver archiveRootObject:_userinfo toFile:kFilePath];
}

- (void)removeAccount {
    _userinfo.accountId = @"";
    _userinfo.accountTypeId = @"";
    _userinfo.accountTypeName = @"";
    _userinfo.createDate = @"";
    _userinfo.headPath = @"";
    _userinfo.lastLoginDate = @"";
    _userinfo.logstringimes = @"";
    _userinfo.name = @"";
    _userinfo.nickName = @"";
    _userinfo.serial = @"";
    _userinfo.sex = @"";
    _userinfo.token = @"";
    
    
    [NSKeyedArchiver archiveRootObject:_userinfo toFile:kFilePath];
}

- (BOOL)isLogin {
    return Token !=nil;
}

@end
